#pragma once
#ifndef CLIENTTOLINUX_H
#define CLIENTTOLINUX_H

#include <iostream>
#include <sys/time.h>           //  for function ->  gettimeofday(&tval, NULL);

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>

#include <thread>
#include <condition_variable>
#include <mutex>

//Socket
#include <arpa/inet.h>
#include <sys/shm.h>
#include<errno.h>

#include <netinet/in.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>


#include <json/json.h>          //new version
#include "computeTime.h"

#define QUEUE 20            //连接请求队列
#define ServiceIp "127.0.0.1"
#define PORT 8000


static bool isTempAlarm;
static string TempAlarmImagePath = "null";

static mutex mutexSocketSend;
void socketSend(const int connfd, const string info);

void recvThread(struct ClientInfo* pinfo);

void clientToLinux(void *arg);
void working(void* arg);


int string2Json(const std::string &info, Json::Value &root);
std::string hearBeatInit(const string robotName);
std::string helloBeatInit(const string robotName);
int sendTempAlarmInfo(const int connfd, const string &imgStr);
void sendHeartBeat(const int connfd);

// struct TempAlarm
// {
//     bool *bTempAlarm ;
//     char* tempAlarmImgPath;

//     float *TempMax;
//     float *TempMin;
//     float *TempAvg;
//     float *TempDiff;

// };

struct ClientInfo
{
    /* data */
    struct sockaddr_in addr;
    int connfd;

    bool *bExitClientToLinux;

    struct TempAlarm* tempAlarmInfo;

};

static mutex mutexClient;
    static struct TempAlarm *pTempAlarmInfo;

static bool ready = false;   // 全局标志位.
static std::mutex mutexTempAlarm;
    static struct ClientInfo *pClientInfo_in;

// static mutex mutexExitHeart;
    //bool bExitHeart = false;

static mutex mutexExitClient;
    static bool bExitClient = false;


#endif